package com.luckcoder.relax.games.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import com.luckcoder.relax.games.domain.vo.RelaxAudioConfigVo;
import com.luckcoder.relax.games.domain.bo.RelaxAudioConfigBo;
import com.luckcoder.relax.games.service.IRelaxAudioConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 音效配置
 *
 * @author zhanghao
 * @date 2025-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/relax/audioConfig")
public class RelaxAudioConfigController extends BaseController {

    private final IRelaxAudioConfigService relaxAudioConfigService;

    /**
     * 查询音效配置列表
     */
    @SaCheckPermission("relax:audioConfig:list")
    @GetMapping("/list")
    public TableDataInfo<RelaxAudioConfigVo> list(RelaxAudioConfigBo bo, PageQuery pageQuery) {
        return relaxAudioConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出音效配置列表
     */
    @SaCheckPermission("relax:audioConfig:export")
    @Log(title = "音效配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RelaxAudioConfigBo bo, HttpServletResponse response) {
        List<RelaxAudioConfigVo> list = relaxAudioConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "音效配置", RelaxAudioConfigVo.class, response);
    }

    /**
     * 获取音效配置详细信息
     *
     * @param audioId 主键
     */
    @SaCheckPermission("relax:audioConfig:query")
    @GetMapping("/{audioId}")
    public R<RelaxAudioConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long audioId) {
        return R.ok(relaxAudioConfigService.queryById(audioId));
    }

    /**
     * 新增音效配置
     */
    @SaCheckPermission("relax:audioConfig:add")
    @Log(title = "音效配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RelaxAudioConfigBo bo) {
        return toAjax(relaxAudioConfigService.insertByBo(bo));
    }

    /**
     * 修改音效配置
     */
    @SaCheckPermission("relax:audioConfig:edit")
    @Log(title = "音效配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RelaxAudioConfigBo bo) {
        return toAjax(relaxAudioConfigService.updateByBo(bo));
    }

    /**
     * 删除音效配置
     *
     * @param audioIds 主键串
     */
    @SaCheckPermission("relax:audioConfig:remove")
    @Log(title = "音效配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{audioIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] audioIds) {
        return toAjax(relaxAudioConfigService.deleteWithValidByIds(List.of(audioIds), true));
    }
}
